package com.llyb.controller;

import cn.hutool.core.date.DateTime;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DeepSeekController
{
    // V1
    @Resource
    private DeepSeekChatModel deepSeekChatModel;

    //V2
    private ChatClient chatClient;
    public DeepSeekController(DeepSeekChatModel deepSeekChatModel)
    {
        this.chatClient = ChatClient.builder(deepSeekChatModel).build();
    }
    //V3
    @Resource
    private ChatModel chatModel;

    //http://localhost:6001/chat
    @GetMapping("/chat")
    public String chat(@RequestParam(name = "question",defaultValue = "你是谁") String question)
    {
        String result = deepSeekChatModel.call(question);
        System.out.println("chat result:" + result);
        return DateTime.now().toString()+"<br> \t"+result;
    }

    @RequestMapping("/chat2")
    public String chat2(@RequestParam(name = "question",defaultValue = "你是谁") String question)
    {
        ChatResponse chatResponse = chatClient.prompt(question).call().chatResponse();
        String result = chatResponse.getResult().getOutput().getText();
        System.out.println("chat2 result:" + result);

        return DateTime.now().toString()+"<br> \t"+result;
    }

    @GetMapping("/chat3")
    public String chat3(@RequestParam(name = "question",defaultValue = "你是谁") String question)
    {
        String result = chatModel.call(question);
        System.out.println("chat3 result:" + result);
        return DateTime.now().toString()+"<br> \t"+result;
    }
}
